
cc.Class({
    extends: cc.Component,

    properties: 
    {
        integral : cc.Label,
        distance : cc.Label,
        control : cc.Node,

        //游戏模块
        game: cc.Node,

        //下滑按钮节点（需要判断离开按钮事件）
        btnSquatNode: cc.Node,
    
        //跳跃按钮节点
        btnJumpNode:cc.Node,
        //能量条
        frame: cc.Node,

        //音频
        soundNode: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad(){
        this.btnSquatNode.on('touchstart', () => {
            this.btnSquat();
        });
        this.btnSquatNode.on('touchend', () => {
            this.unBtnSquat();
        });
        this.btnJumpNode.on('touchstart', () => {
            this.btnJump();
        });
        this.energyFrame = this.frame.getComponent('energyFrame');

        //声音
        this.sound = this.soundNode.getComponent('sound');
    },

    // onLoad () {},
    stopBtn()
    {
        //先停止之前运行的一切逻辑吗？
        this.gameCtrl.stopFun();

        //切换至暂停
        this.control.active = true;
        this.btnSound();
        cc.director.pause();
        

    },
    //返回主界面
    backBtn(){
        cc.director.loadScene('Main');
    },
    playBtn()
    {
        //切换至开始
        this.control.active = false;
        //继续暂停的逻辑？
        cc.director.resume();
        this.btnSound();
    },
    start () 
    {
        this.gameCtrl = this.game.getComponent('gameCtrl');
        // //预加载主界面
        // cc.director.preloadScene('Main', function() {});
    },

    //跳跃
    btnJump(){
        this.gameCtrl.Jump();
        this.btnSound();
    },
    //下滑
    btnSquat(){
        this.gameCtrl.Squat();
        this.btnSound();
    },

    //离开下滑按钮
    unBtnSquat(){
        this.gameCtrl.unSquat();
    },
    //更新金币
    updateGold(count){
        this.integral.string = count;
    },

    //更新路程
    updateS(s) {
        this.distance.string = s;
    },

    //更新御剑飞行能量条
    updateFly(value){
        this.energyFrame.updateenergy(value);
    },

    btnSound(){
        //点击音效
        this.sound.onPlayClick();
    },
    // update (dt) {},
});
